!{include file='common/iheader.htm'}
<div id="i_nav">
	<h3 class="page_title">编辑引用 - !{$dict.word}</h3>
	<a class="button" href="/manager.php?app=wiki&act=recommend&type=0">引用管理</a>
	<a class="button" href="/manager.php?app=wiki">WIKI管理</a>
</div>
<form method="post">
	<div class="tabs">
		<ul>
			<li><a href="#base">基本信息</a></li>
			<li><a href="#images">图片引用</a></li>
		</ul>
		<div id="base">
			<div class="form_item">
				<strong>标题：</strong>
				<input type="text" class="text_input" name="title" value="!{$recommend.title|default:$recommend.word}"/>
			</div>
			<div class="form_item">
				<strong>图片规格：</strong>
				<input type="text" class="text_input" name="width" value="!{$width|default:550}"/> X 
				<input type="text" class="text_input" name="height" value="!{$height|default:282}"/>
			</div>
			<div class="form_item">
				<strong>描述：</strong>
				<textarea style="width:400px" name="desc" value="!{$recommend.desc|default:''}">!{$recommend.desc}</textarea>
			</div>
			<div class="form_item">
				<strong>图片：</strong>
				!{if $recommend.image}
				<img id="show_image" src="!{res file=$recommend.image thumb=150x150}"/>
				<input type="hidden" name="image" value="!{$recommend.image}"/>
				!{else}
				<img id="show_image" src="!{res file='images/no_pic.jpg' thumb=150x150}"/>
				<input type="hidden" name="image" value=""/>
				!{/if}
				<p>点击重新上传或者切换到“图片引用”中选定</p>
			</div>
			<div class="form_item form_btn_item">
				<input type="hidden" name="id" value="!{$smarty.request.id}"/>
				<input type="hidden" name="rid" value="!{$smarty.request.rid}"/>
				<input type="submit" value="保存" class="button submit_btn">
			</div>
		</div>
		<div id="images">
			!{foreach from=$dict.items item=index}
			!{foreach from=$index.images item=img}
			<img class="lazy" src="!{res file='images/grey.gif'}" width="150px" height="150px" data-original="!{res file=$img.file thumb=150x150}"/>
			!{/foreach}
			!{/foreach}
		</div>
	</div>
</form>
<script language="javascript" src="!{res file='js/jquery_plus/ajaxupload.js'}"></script> 
<script src="!{res file='js/jquery_plus/jquery.lazyload.min.js'}"></script>
<script>
	var options = {
		action : '/index.php?app=site&act=upload',
        name: 'imgFile',
        autoSubmit: true,
        onSubmit : function(file, ext){
            if (ext && /^(jpg|png|jpeg|gif)$/i.test(ext)){
            } else {
                alert('非图片类型文件！');
                return false;              
            }
            this.disable();
        },
        onComplete: function(file, response){
            var json = null;
            try{
	            json = eval('(' + response + ')');
            }catch(e){
            	alert('发生错误，请重试！');
            	this.enable();
                return;
            }
            if(json.error == 0){
				var img_path = json.url;
				//转换规格
				img_path = img_path.replace(/^(.*)\/([^\/]*)$/g, "$1/150x150/$2");
				
            	//上传成功
            	$('#show_image').attr('src', img_path);
            	$('input[name="image"]').val(img_path);
            }else{
            	alert('上传失败');
            }
            this.enable();
        }
	};
	
	$(function(){
		$('img.lazy').lazyload({
			effect : 'fadeIn',
			threshold : 100, 
			load : function(){
				$(this).removeAttr('height').removeAttr('width').auto_img();
			}
		}).click(function(){
			var img_path = $(this).attr('src');
           	$('#show_image').attr('src', img_path);
           	$('input[name="image"]').val(img_path);
           	$('.tabs').tabs('select', 0);
		});
		
		new AjaxUpload($("#show_image"), options);
	});
</script>
!{include file='common/ifooter.htm'}